POV-Ray : Newsgroups : povray.general : Macro Parameters : Re: Macro Parameters Server Time
12 Aug 2024 13:23:44 EDT (-0400)
  Re: Macro Parameters  
From: John VanSickle
Date: 7 Feb 1999 14:28:11
Message: <36BDEA43.B2B38108@erols.com>
BC wrote:
> 
> Can anyone tell me how you pass an array to a macro. I have looked at the
> docs, and they don't say you can't, but I can't figure out the syntax to do
> so.

It's easy.  Just pass the label for the array, and index into it within
the macro.

For instance you can declare it as follows:

#macro Average(Array)
  #local I=1;
  #local Sum=Array[0]; // so that Sum is created as the same type as Array[]
  #while (I<dimension_size(Array,1))
  #local Sum=Sum+Array[I];
  #local I=I+1;
  #end
  (Sum/I)
#end

And then use it like this:

#declare BugaBoo=array[4] { 34,5,-17,8 }
#declare BugaBee=array[3] { <1,0,3>,x+y, <.3,.3,-.1>+z*2 }

#local s_ScalarAverage=Average(BugaBoo);
#local s_VectorAverage=Average(BugaBee);

Hope this helps,
John


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.